package com.wukong.alive;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.AppUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

public class SelectAppActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    AppAdapter appAdapter;
    List<AppUtils.AppInfo> datas;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_app);
        recyclerView= findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        datas= AppUtils.getAppsInfo();
        appAdapter=new AppAdapter(datas);
        recyclerView.setAdapter(appAdapter);

        appAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent=new Intent();
                intent.putExtra("package",datas.get(position).getPackageName());
                setResult(Activity.RESULT_OK,intent);
                finish();
            }
        });

    }
}